/**
 *
 * @authors supmain (mtingfeng@gmail.com)
 * @date    2014-08-16 12:01:58
 * @update  2014-08-16 12:01:58
 * @for webapp.html
 * @version $Id$
 */
$(function() {
    $('#slides').slides({
        preload: true,
        play: 3000,
        pause: 2500,
        hoverPause: true
    });

    $('#img_ul').bxCarousel({
        display_num: 4,
        move: 1,
        margin: 10,
        next_image: "images/next-no.gif",
        prev_image: "images/pre-no.gif"
    });

});


//多条件查询
function zzfwReload(page) {
	var industryId = $("#industry").val(),
		productCategoryId = $("#product_category").val(),
        productName = $("#textfield2").val();
	if(productName == '关键字') {
		productName = "";
	}
	
	var data_param = {
		mealId: $("#mealId").val(),
		industryId: industryId,
		productCategoryId: productCategoryId,
		productName: productName,
		page : page
	};
	$.ajax({
		type:"POST",
		url:"/mall/yyzzfw/search",
		data:data_param,
		async:false,
		dataType:"json",
		success:function(data){
			//增值服务套餐产品数量
			$('#num').html(data.totalRows);
			$('#page').val(data.page);
			$('#pageCount').val(data.pageCount);
			
			//增值服务套餐产品查询
			var zzfw = "";
			$("#zzfw").empty();
			$.each(data.mpVo,function(index,p){
				if(data.mpVo.length > 0) {
					if(index > 1){
						zzfw += '<div class="layout fl mt20">';
					}else {
						zzfw += '<div class="layout fl">';
					}
					
					zzfw +='<div class="pic fl mr20">'+
				            '<a href="/mall/cpxq/'+p.productId+'">'+
				                '<img src="'+p.productImg+'" width="75" height="75" />'+
				            '</a>'+
				            '</div>'+
				            '<dl class="fl">'+
				            '<dt><a href="/mall/cpxq/'+p.productId+'">'+p.productName+'</a></dt>'+
				            '<dd>'+
				                '<font class="red">报价：￥'+p.productPrice+'</font></dd>'+
				            '<dd>'+p.productBrief+'</dd>'+
				            '</dl>'+
				            '<div class="kt-btn"><a href="/mall/cpxq/'+p.productId+'" class="fr">购买</a>'+
				            '</div>'+
				            '<div class="cl"></div>'+
				            '</div>';
				}
				
			})
			zzfw +='<div class="cl"></div>'+
					'<div class="page mt20" align="center">共'+data.totalRows+'条记录 '+data.page+'/'+data.pageCount+'页&nbsp;'+
					'<a href="javascript:zzfwReload(1)">&nbsp;首页</a> <a onclick="javascript:ajaxPageUp('+data.page+')">上一页</a>&nbsp;'+
					'<a onclick="javascript:ajaxPageDown('+data.page+');">&nbsp;下一页</a>&nbsp;'+
					'<a href="javascript:zzfwReload('+data.pageCount+')" >尾页</a>&nbsp;&nbsp;第&nbsp;&nbsp;'+
					'<select onchange="ajax2Page()" id="currPage">';
			for(var i = 1; i <= data.pageCount; i++) {
				zzfw += '<option value="'+i+'" ';
				if(data.page == i) {
					zzfw += 'selected="selected"';
				}
				zzfw += '>'+i+'</option>';
			}
			zzfw += '</select>&nbsp;页</div>';		
			$("#zzfw").append(zzfw);
		}
	
	})
}

function ajax2Page() {
	zzfwReload($('#currPage').val());
}

//向上翻页
function ajaxPageUp(page) {
	if(page == 1) {
		BSTYUN.dialog.warn("已经是第一页");
		return;
	}else {
		var num = parseInt(page) - 1;
		zzfwReload(num);
	}
}

//向下翻页
function ajaxPageDown(page) {
	if(page == $("#pageCount").val()) {
		BSTYUN.dialog.warn("已经是最后一页");
		return;
	}else {
		var num = parseInt(page) + 1;
		zzfwReload(num);
	}
}